//
//  EvaluationDetailVC.m
//  ForestPack
//
//  Created by jimmy on 2018/7/11.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "EvaluationDetailVC.h"
#import "CommentProgressCell.h"
#import "HMSegmentedControl.h"
#import "SimpleHeaderView.h"
#import "FPCommodityDetailCell.h"
#import "Masonry.h"
#import "CommentDetailTool.h"
#import "EmployerCommentTool.h"
#import "EmployerCommentModel.h"

@interface EvaluationDetailVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)  BaseTableView     * tableView;

@property (nonatomic,strong)  NSMutableArray       * commentArray;
@property (nonatomic,strong)  NSMutableArray       * employerCommentArray;
@property (nonatomic,strong)  EmployerCommentModel * employerCommentModel;

@end

@implementation EvaluationDetailVC

- (NSMutableArray *)employerCommentArray
{
    if (_employerCommentArray == nil) {
        _employerCommentArray = [[NSMutableArray alloc] init];
    }
    return _employerCommentArray;
}

- (NSMutableArray *)commentArray
{
    if (_commentArray == nil) {
        _commentArray = [[NSMutableArray alloc] init];
    }
    return _commentArray;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self setTitle:@"评价详情"];
    [self setTableViewUI];
    
    [self requestCommentDetailData];
}

-(void)requestCommentDetailData
{
//    [CommentDetailTool refreshCommentDetailDataWithRequestStatus:0 withGoods_id:[self.design_id integerValue] withGrade:3 withCurrent_page:1 withType:9 success:^(CommentDetailModel *commentDetailModel) {
//        [self.commentArray addObject:commentDetailModel.data];
//        [self.tableView reloadData];
//    }];
    
    [EmployerCommentTool requestCommentShowDataWithGoods_id:[self.design_id integerValue] withType:9 success:^(EmployerCommentModel *employerCommentModel) {
        self.employerCommentModel = employerCommentModel;
        [self.employerCommentArray addObject:employerCommentModel];
    }];
}

-(void)segmentDidChangedValue
{
    
}

-(void)setTableViewUI
{
    self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT) style:UITableViewStyleGrouped];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.tableView.sectionFooterHeight = 10;

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 2) {
        return self.commentArray.count;
    }
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0){
        return ScreenX375(90);
    }else if (indexPath.section == 1){
        return ScreenX375(65);
    }else{
        return ScreenX375(160);
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 0 || section == 1){
        return ScreenX375(53);
    }else{
        return ScreenX375(64);
    }
    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if(section == 0){
        SimpleHeaderView *view = [SimpleHeaderView headerViewWithTitle:@"雇主评价" withHeight:ScreenX375(53)];
        view.backgroundColor = [UIColor whiteColor];
        return view;
    }else if (section == 1){
        SimpleHeaderView *view = [SimpleHeaderView headerViewWithTitle:@"雇主印象" withHeight:ScreenX375(53)];
        view.backgroundColor = [UIColor whiteColor];
        return view;
    }else{
        UIView *view = [[UIView alloc] init];
        UIView *bjView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(54))];
        bjView.backgroundColor = [UIColor whiteColor];
        [view addSubview:bjView];
        HMSegmentedControl *segment = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"好评\n9",@"中评\n8",@"差评\n9"]];
        segment.frame = CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(54));
        segment.backgroundColor = [UIColor clearColor];
        segment.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
        segment.autoresizingMask = UIViewAutoresizingFlexibleWidth |  UIViewAutoresizingFlexibleRightMargin;
        segment.titleTextAttributes = @{NSForegroundColorAttributeName:FONTCOLOR_BLACK,NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size:12]};
        //设置选项卡被选中的颜色
        segment.selectedTitleTextAttributes = @{NSForegroundColorAttributeName:RGB_COLOR(237,34,59),NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size:12]};
        segment.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
        segment.selectionIndicatorHeight = 2;
        segment.selectionIndicatorColor = RGB_COLOR(237,34,59);
        //设置开始时默认选中的下标
        segment.selectedSegmentIndex = 0;
        //设置选中的选项卡的点击事件
        [segment addTarget:self action:@selector(segmentDidChangedValue) forControlEvents:UIControlEventValueChanged];
        [bjView addSubview:segment];
        
        return view;
    }    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 1){
        FPTagListCell *tagListCell = [FPTagListCell cellWithTableView:tableView andIndexPath:indexPath];
        if(tagListCell == nil){
            tagListCell = [[FPTagListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FPTagListCell"];
        }
        if (self.employerCommentArray.count > 0) {
            tagListCell.employerCommentModel = self.employerCommentArray[0];
        }
        
        return tagListCell;
    }else if (indexPath.section == 2){
        FPCommodityThirdCell *cell = [FPCommodityThirdCell cellWithTableView:tableView andIndexPath:indexPath];
        if (self.employerCommentArray.count > 0) {
            [cell updateRecordDetailDataModel:self.commentArray[0]];
        }
        return cell;
    }
    CommentProgressCell *cell = [CommentProgressCell cellWithTableView:tableView andIndexPath:indexPath];
    if (self.employerCommentArray.count > 0) {
        cell.employerCommentModel = self.employerCommentArray[0];
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:false];
}

-(void)setSecondSctionHeaderUI
{
    
    
    
    
    
}

@end
